package kr.hkit.powerjava.chapter15;

import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.Random;

import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class MyImageFrame1  extends JFrame implements ActionListener{
	BufferedImage img;
	private int pieces=4;
	private int totalPieces=pieces*pieces;
	private int[] pieceNumber;
	
	public MyImageFrame1(){
		//이미지 읽는다
		setTitle("이미지 그리기");
		try {
			img=ImageIO.read(new File("수국화.jpg"));
		} catch (Exception e) {
			System.out.println(e.getMessage());
			System.exit(0);
		}
		pieceNumber= new int[totalPieces];
		for(int i=0; i<totalPieces;i++){
			pieceNumber[i]=0;
		}
		add(new MyPanel(),BorderLayout.CENTER);
		JButton button= new JButton("나누기");
		button.addActionListener(this);
		add(button,BorderLayout.SOUTH);
		setSize(600, 600);
		setVisible(true);
	}
	//사진분할메서드
	void divide(){
		Random random= new Random();
		int rani;
		for(int i=0;i<totalPieces;i++){
			rani=random.nextInt(totalPieces);
			int tmp=pieceNumber[i];
			pieceNumber[i]=pieceNumber[rani];
			pieceNumber[rani]=tmp;
		}
	}
	class MyPanel extends JPanel{
		public void paintComponent(Graphics g){
			
		}
	}
	
	
	
	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		
	}

}
